package com.pocketsweet.ui;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;

import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ContentView;
import com.pocketsweet.MLApplication;
import com.pocketsweet.R;
import com.pocketsweet.ui.fragments.WelcomeFour;
import com.pocketsweet.ui.fragments.WelcomeOne;
import com.pocketsweet.ui.fragments.WelcomeThree;
import com.pocketsweet.ui.fragments.WelcomeTwo;
import com.pocketsweet.ui.uilib.MyFragmentPagerAdapter;

@ContentView(R.layout.activity_welcome)
public class Welcome extends FragmentActivity {
	private ViewPager mMainViewPager = null;
	private List<Fragment> fragments;
	private WelcomeOne welcomeOne;
	private WelcomeTwo welcomeTwo;
	private WelcomeThree welcomeThree;
	private WelcomeFour welcomeFour;
	public MLApplication mlApplication;


	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		ViewUtils.inject(this);
		mlApplication = MLApplication.getInstance();
		mlApplication.addActivity(this);
		initView();
	}

	private void initView() {
		mMainViewPager = (ViewPager) findViewById(R.id.pager);
		fragments = new ArrayList<Fragment>();
		welcomeOne = new WelcomeOne();
		welcomeTwo = new WelcomeTwo();
		welcomeThree = new WelcomeThree();
		welcomeFour = new WelcomeFour();
		fragments.add(welcomeOne);
		fragments.add(welcomeTwo);
		fragments.add(welcomeThree);
		fragments.add(welcomeFour);
		mMainViewPager.setAdapter(new MyFragmentPagerAdapter(
				getSupportFragmentManager(), fragments));
		mMainViewPager.setOnPageChangeListener(new OnPageChangeListener() {

			@Override
			public void onPageSelected(int position) {
//				if (position == 0) {
//					welcomeOne.textShow();
//				} else if (position == 1) {
//					welcomeTwo.textShow();
//				} else if (position == 2) {
//					welcomeThree.textShow();
//				}
			}

			@Override
			public void onPageScrolled(int position, float positionOffset,
					int positionOffsetPixels) {
			}

			@Override
			public void onPageScrollStateChanged(int arg0) {

			}
		});
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		mlApplication.removeActivity(this);
	}
	
	@Override
	protected void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
	}

	@Override
	protected void onRestoreInstanceState(Bundle savedInstanceState) {
		super.onRestoreInstanceState(savedInstanceState);
	}
	
}
